package com.ezjie.ielts.module_word.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.ezjie.ielts.R;
import com.ezjie.ielts.model.TestOfflineBean;

public class OfflineAdapter extends BaseAdapter {
	private Context mContext;
	private List<TestOfflineBean> list;

	public OfflineAdapter(Context context) {
		this.mContext = context;
	}

	public void setList(List<TestOfflineBean> list) {
		this.list = list;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return list == null ? 0 : list.size();
	}

	@Override
	public boolean areAllItemsEnabled() {
		return false;
	}

	@Override
	public boolean isEnabled(int position) {
		// 如果是 标题栏目 返回false
		return super.isEnabled(position);
	}

	@Override
	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return arg0;
	}

	@Override
	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return arg0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder = null;

		convertView = LayoutInflater.from(mContext).inflate(R.layout.layout_offline_listview_item, null);
		holder = new ViewHolder();
		holder.tv_offline_name = (TextView) convertView.findViewById(R.id.tv_offline_name);
		holder.iv_download = (ImageView) convertView.findViewById(R.id.iv_download);
		holder.pb_loading = (ProgressBar) convertView.findViewById(R.id.pb_loading);

		convertView.setTag(holder);

		TestOfflineBean testOfflineBean = list.get(position);
		if (testOfflineBean != null) {
			if (testOfflineBean.isTitle()) {
				TextView textView = (TextView) LayoutInflater.from(mContext).inflate(
						R.layout.layout_offline_title_listview_item, null);
				textView.setText(testOfflineBean.getName());
				return textView;
			} else {

			}
			holder.tv_offline_name.setText(testOfflineBean.getName());
		}

		return convertView;
	}

	class ViewHolder {
		TextView tv_offline_name;
		ImageView iv_download;
		ProgressBar pb_loading;

	}

}
